package com.learn.seven;

import org.apache.log4j.Logger;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/15
 */
public class TestSequence {
    static final Logger log=Logger.getLogger(TestSequence.class);

    static final Object lock = new Object();
//    表示t2是否运行过
    static boolean t2runned = false;

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (lock){
                while (!t2runned){
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                log.debug("打印1");
            }

        }, "t1").start();


        new Thread(() -> {
            synchronized (lock){
                log.debug("打印2");
                t2runned=true;
                lock.notifyAll();
            }
        }, "t2").start();
    }
}
